package Underworld_Survival;

import java.io.Serializable;

import static Underworld_Survival.Game.gameOutput;

// 装备特殊效果接口
public interface EquipmentSpecialEffect extends Serializable {
    // 绑定到战斗阶段的生命周期方法
    default void onAttackStart(BattleManager battleCtx) {}    // 攻击开始时(释放了技能，还没进行伤害计算)
    default void onDamageCalculated(BattleManager battleCtx) {} // 伤害计算后(伤害可能为0被闪避，不为0，具体数值)
    default void onAttackHit(BattleManager battleCtx) {}      // 攻击命中时(敌人受伤)
    default void onAttackEnd(BattleManager battleCtx) {}      // 攻击结束后(我方回合结束，进入敌方回合)
    default void afterInjured(BattleManager battleCtx){}      //被攻击命中，受伤后
    default void beforeBattle(BattleManager battleCtx){}      //特殊装备，战斗之前可能有动作
    default void afterBattle(BattleManager battleCtx){}       //特殊装备，战斗之后可能有动作

}

//特殊效果的实现
//灼烧效果
class FlameEffect implements EquipmentSpecialEffect {
    private final float triggerChance;//效果触发概率
    public FlameEffect(float chance) {this.triggerChance = chance;}

    @Override
    public void onAttackStart(BattleManager battleCtx) {
        if(battleCtx.getInjuryValue()>0) {//攻击未被闪避
            if(battleCtx.getTarget()!=null&&Math.random() < triggerChance){//被攻击者列表不为空
                gameOutput.println(GameOutput.MsgType.EVENT,"敌人烧起来了！");
                battleCtx.getTarget().addBuff(new burning());
            }else{
                System.out.println("！！！返回空敌人列表！！！");
            }
        }
    }
}
//反伤效果
class DamageReflectionEffect implements EquipmentSpecialEffect {
    private final float triggerChance;//效果触发概率
    public DamageReflectionEffect(float chance) {this.triggerChance = chance;}

    @Override
    public void afterInjured(BattleManager battleCtx) {
        if(battleCtx.getInjuryValue()>0) {//攻击未被闪避
            if(battleCtx.getAttacker()!=null){//存在攻击者
                int value=(int)(battleCtx.getInjuryValue()*0.25);//目前固定反伤25%
                if(value!=0) gameOutput.println(GameOutput.MsgType.INJURE,"反伤"+value+"点!");
                battleCtx.getAttacker().reduceHP(value);
            }else{
                System.out.println("！！！没有攻击者，无法反伤！！！");
            }
        }
    }
}
//先发制人效果
class preemptEffect implements EquipmentSpecialEffect{
    private final float triggerChance;//效果触发概率
    public preemptEffect(float chance) {this.triggerChance = chance;}
    @Override
    public void beforeBattle(BattleManager battleCtx){
        battleCtx.setIsPlayerTurn(true);
        gameOutput.println(GameOutput.MsgType.INCREASE,"破先！先发制人");
    }
}
